<script>
const SimpleView = {
  name: 'Simple',
  text: '',
};
export default {
  data() {
    return {
      com: {},
    };
  },
  methods: {
    /**
     * 发送跳转动作
     */
    redirect(action) {
      this.$root.$EventBus.stack('redirect', action);
    },
    /**
     * 执行跳转
     */
    onRedirect(action) {
      if (!this.beforeRedirect(action)) return false;
      // 本地处理 通过Simple作为跳板，防止错误的重复利用
      this.com = SimpleView;
      return this.$HttpSend(action).then((response) => {
        const rs = JSON.parse(JSON.stringify(response));
        if (rs.view) this.com = rs.view;
        this.afterRedirect(rs);
        throw new Error('route');
      }).catch(() => {});
    },
    beforeRedirect(action) {
      return action && (!action.layer || action.layer === this.$options.name);
    },
    /**
     * 跳转完成钩子
     */
    afterRedirect() {
    },
  },
};
</script>

